home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-30 | 1.2 KB | 59 lines | [TEXT/PJMM] |
- unit MyThreads;
-
- interface
-
- uses
- Threads;
-
- var
- active_threads: integer; { YOU MUST DECREMENT active_threads }
-
- procedure InitMyThreads;
- procedure FinishMyThreads;{ waits for all threads to complete - ie active_threads=0 }
- procedure MyNewThread (proc: ProcPtr; threadParam: univ Ptr); { increments active_thread }
- procedure MyYield;
-
- implementation
-
- uses
- {$IFC undefined THINK_Pascal}
- Events,
- {$ENDC}
- MyAssertions;
-
- const
- our_thread_stack = 16000;
- our_thread_options = kCreateIfNeeded + kUsePremadeThread + kFPUNotNeeded;
-
- procedure MyNewThread (proc: ProcPtr; threadParam: univ Ptr);
- var
- thread: ThreadID;
- begin
- Assert(NewThread(kCooperativeThread, proc, threadParam, our_thread_stack, our_thread_options, nil, thread) = noErr);
- active_threads := active_threads + 1;
- end;
-
- procedure MyYield;
- var
- junk: OSErr;
- begin
- Assert(YieldToAnyThread = noErr);
- end;
-
- procedure InitMyThreads;
- begin
- active_threads := 0;
- end;
-
- procedure FinishMyThreads;{ waits for all threads to complete - ie active_threads=0 }
- var
- er: EventRecord;
- dummy: boolean;
- begin
- while active_threads > 0 do begin
- dummy := WaitNextEvent(everyEvent, er, 0, nil);
- MyYield;
- end;
- end;
-
- end.